设置Linux命令或者shell脚本的运行时间限制

您所在的位置:网站首页 shell脚本 while done能输入一段命令吗 设置Linux命令或者shell脚本的运行时间限制

设置Linux命令或者shell脚本的运行时间限制

2024-07-09 22:44:49| 来源: 网络整理| 查看: 265

有些shell脚本或者命令,只有在规定时间内运行完成才有意义,这时可以设置脚本/命令的时间限制,如果在设定时间内,还没有完成,则终止命令/脚本。可以使用timeout命令来做到,先看一下它的用法:

$ man timeout TIMEOUT(1) User Commands TIMEOUT(1) NAME timeout - run a command with a time limit SYNOPSIS timeout [OPTION] DURATION COMMAND [ARG]... timeout [OPTION] DESCRIPTION Start COMMAND, and kill it if still running after DURATION. Mandatory arguments to long options are mandatory for short options too. --preserve-status exit with the same status as COMMAND, even when the command times out --foreground When not running timeout directly from a shell prompt, allow COMMAND to read from the TTY and receive TTY signals. In this mode, children of COMMAND will not be timed out. -k, --kill-after=DURATION also send a KILL signal if COMMAND is still running this long after the initial signal was sent. -s, --signal=SIGNAL specify the signal to be sent on timeout. SIGNAL may be a name like 'HUP' or a number. See 'kill -l' for a list of signals --help display this help and exit --version output version information and exit DURATION is a floating point number with an optional suffix: 's' for seconds (the default), 'm' for minutes, 'h' for hours or 'd' for days. If the command times out, and --preserve-status is not set, then exit with status 124. Otherwise, exit with the status of COMMAND. If no signal is specified, send the TERM signal upon timeout. The TERM signal kills any process that does not block or catch that signal. It may be necessary to use the KILL (9) signal, since this signal cannot be caught, in which case the exit status is 128+9 rather than 124. BUGS Some platforms don't curently support timeouts beyond 2038 AUTHOR Written by Padraig Brady. REPORTING BUGS Report timeout bugs to [email protected] GNU coreutils home page: General help using GNU software: Report timeout translation bugs to COPYRIGHT Copyright 2013 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later . This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent per鈥[m mitted by law. SEE ALSO kill(1) The full documentation for timeout is maintained as a Texinfo manual. If the info and timeout programs are properly installed at your site, the command info coreutils 'timeout invocation' should give you access to the complete manual. GNU coreutils 8.21 March 2016 TIMEOUT(1)

示例1,假设有如下脚本,每隔一秒钟输出一次系统时间 qingsong@db2a:~$ cat infiniteloop.sh #!/bin/bash while true do     echo -n "Current date: "     date     sleep 1 done

qingsong@db2a:~$ bash infiniteloop.sh Current date: Thu Aug 17 02:48:15 PDT 2017 Current date: Thu Aug 17 02:48:16 PDT 2017 Current date: Thu Aug 17 02:48:17 PDT 2017 Current date: Thu Aug 17 02:48:18 PDT 2017 Current date: Thu Aug 17 02:48:19 PDT 2017 Current date: Thu Aug 17 02:48:20 PDT 2017 Current date: Thu Aug 17 02:48:21 PDT 2017 Current date: Thu Aug 17 02:48:22 PDT 2017 Current date: Thu Aug 17 02:48:23 PDT 2017 ^C



【本文地址】

公司简介

联系我们

今日新闻


点击排行

实验室常用的仪器、试剂和
说到实验室常用到的东西,主要就分为仪器、试剂和耗
不用再找了,全球10大实验
01、赛默飞世尔科技(热电)Thermo Fisher Scientif
三代水柜的量产巅峰T-72坦
作者:寞寒最近,西边闹腾挺大,本来小寞以为忙完这
通风柜跟实验室通风系统有
说到通风柜跟实验室通风,不少人都纠结二者到底是不
集消毒杀菌、烘干收纳为一
厨房是家里细菌较多的地方,潮湿的环境、没有完全密
实验室设备之全钢实验台如
全钢实验台是实验室家具中较为重要的家具之一,很多

推荐新闻


图片新闻

实验室药品柜的特性有哪些
实验室药品柜是实验室家具的重要组成部分之一,主要
小学科学实验中有哪些教学
计算机 计算器 一般 打孔器 打气筒 仪器车 显微镜
实验室各种仪器原理动图讲
1.紫外分光光谱UV分析原理:吸收紫外光能量,引起分
高中化学常见仪器及实验装
1、可加热仪器:2、计量仪器:(1)仪器A的名称:量
微生物操作主要设备和器具
今天盘点一下微生物操作主要设备和器具,别嫌我啰嗦
浅谈通风柜使用基本常识
 众所周知,通风柜功能中最主要的就是排气功能。在

专题文章

    CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭